package com.eascs.crm.web.service;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import com.eascs.crm.server.manger.impl.BaseDao;
import com.eascs.crm.web.constant.CacheNameConstant;
import com.eascs.site.tag.select.SelectDataService;

@Service
public class SelectDataServiceImpl  implements SelectDataService {

	@Autowired
	BaseDao baseDao;
	
	@Cacheable(CacheNameConstant.SELECT_DATA)
	public List<Object[]> getDataSouce(String dataSouceType, String dataSouceFrom) {
		
		List<Object[]> dataSouceList = new ArrayList<>();
		List<Object> listParams = new ArrayList<Object>();
		StringBuffer sql = new StringBuffer("SELECT item.item_code,item.item_name FROM pub_dditem item"); 
               sql.append(" where item.dd_no = (select dic.dd_no  from 	pub_datadictionary dic  where 1=1");
               if (dataSouceType != null && !"".equals(dataSouceType)) {
          			sql.append(" and dd_code= ? )");
          			listParams.add(dataSouceType);
          		   }
               if (dataSouceFrom != null && !"".equals(dataSouceFrom)) {
       			sql.append(" and parent_code= ?");
       			listParams.add(dataSouceFrom);
       		   }
		sql.append(" order by  item_code  asc ");
		dataSouceList = baseDao.findObjectsList(sql.toString(),listParams.toArray());
		


		return dataSouceList;
	}

}
